<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="fyhRepairStuff"
      :isSelectColumn="false"
      :columns="columns"
      :height="300"
      :dataSource="saleStuffList"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { all } from 'q';
import { querySellMaterial, queryChargeDifferentiationList } from '@/api/repair/repairReception/repairBusinessManger';

export default {
  name: 'RepairPro',
  mixins: [dictionary],
  props: ['dataList', 'roNo'],
  data() {
    return {
      columns: this.createTableColumns(),
      saleStuffList: []
    };
  },

  mounted() {
    this.querySeMaterial(); // 销售材料查询
    this.queryChargeList();
  },

  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          width: 150,
          sorter: true,
          filter: true,
          editable: false,
          defaultEditable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '库位代码',
        //   dataIndex: 'STORAGE_POSITION_CODE',
        //   width: 150,
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '计量单位',
          dataIndex: 'UNIT_NAME',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件销售数量',
          dataIndex: 'PART_QUANTITY',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '备件成本金额',
          dataIndex: 'LABOUR_PRICE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '成本价',
          dataIndex: 'PART_COST_PRICE',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },

        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '是否入账',
          dataIndex: 'IS_FINISHED',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1278'),
          render: props => {
            return <span>{this.createDictText(props.row.IS_FINISHED, '1278')}</span>;
          }
        }
      ];
    },

    createBaseTable() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },

    // 查询收费区分
    async queryChargeList() {
      const res = await queryChargeDifferentiationList();
      // console.log(res, 'res');
      this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = res.data.map(x => ({
        value: x.CHARGE_PARTITION_CODE + '',
        text: x.CHARGE_PARTITION_NAME
      }));
    },

    // 传给父组件
    // syncTableFun(val) {
    //   if (val && val.length > 0) {
    //     delete val.dataMark;
    //     this.$emit('syncTablelist', val);
    //   } else {
    //     this.$emit('syncTablelist', []);
    //   }
    //   // console.log(val, '表格数据');
    // },

    // 销售材料查询
    async querySeMaterial() {
      const roNo = this.roNo;
      // const res = await querySellMaterial(roNo);
      // console.log(res,'res')
      const res = (await querySellMaterial(roNo)).data.rows;
      this.saleStuffList = res;
    }
  }
};
</script>

<style lang="less"></style>
